'''
Created on Sep 5, 2010

@author: diego
'''

import cv
 

vinf=0
 
def onchangeval(val):
    global vinf
    vinf=val
def onchangecigar(val):
    global hinf
    hinf=val
def onchangecigarhigh(val):
    global hsup
    hsup=val

if __name__ == '__main__':
    global vinf
    cv.NamedWindow("test")
    cv.CreateTrackbar("valor", "test", 170, 255, onchangeval)
    capture=cv.CreateCameraCapture(1)
    while(1):
        img=cv.QueryFrame(capture)
        gray=cv.CreateImage(cv.GetSize(img),8, 1)
        hsv=cv.CreateImage(cv.GetSize(img),8, 3)
        output=cv.CreateImage(cv.GetSize(img),8, 1)
        cv.ShowImage("rgb plano", img)
        cv.CvtColor(img,gray,cv.CV_RGB2GRAY)
        cv.CvtColor(img,hsv,cv.CV_RGB2HSV)
        cv.Threshold(gray, gray, 100, 255, cv.CV_THRESH_BINARY)
        cv.ShowImage("grayscale", gray)
        inf=cv.Scalar(0,0,vinf)
        sup=cv.Scalar(255,300,300)
        cv.InRangeS(hsv, inf, sup, output)
        cv.ShowImage("test", output)
        cv.WaitKey(20)
    
    